<?php
namespace app\home\controller;

use think\Controller;
class Index extends Controller
{
    public function Index()
    {

//        热门排行
        // CURL 初始化
        $curl5 = curl_init();
        $showapi_appid = '79489';  //替换此值,在官网的"我的应用"中找到相关值
        $showapi_secret = '1164663efbe048bcabc9b43fdf3653a6';  //替换此值,在官网的"我的应用"中找到相关值
        $paramArr = array(
            'showapi_appid'=> $showapi_appid,
            'topid'=> "5"
//添加其他参数
        );

//创建参数(包括签名的处理)
        function createParam ($paramArr,$showapi_secret) {
            $paraStr = "";
            $signStr = "";
            ksort($paramArr);
            foreach ($paramArr as $key => $val) {
                if ($key != '' && $val != '') {
                    $signStr .= $key.$val;
                    $paraStr .= $key.'='.urlencode($val).'&';
                }
            }
            $signStr .= $showapi_secret;//排好序的参数加上secret,进行md5
            $sign = strtolower(md5($signStr));
            $paraStr .= 'showapi_sign='.$sign;//将md5后的值作为参数,便于服务器的效验
//            echo "排好序的参数:".$signStr."\r\n";
            return $paraStr;
        }
        $param = createParam($paramArr,$showapi_secret);
        $url5 = 'http://route.showapi.com/213-4?'.$param;
//        echo "请求的url:".$url."\r\n";die;
        // CURL设置
        curl_setopt($curl5, CURLOPT_URL, $url5);
        // 将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl5, CURLOPT_RETURNTRANSFER, true);
        // 设置为不验证证书和host
//        curl_setopt($curl3, CURLOPT_SSL_VERIFYPEER, false);
//        curl_setopt($curl3, CURLOPT_SSL_VERIFYHOST, false);
        // CURL  执行
        $data5 = curl_exec($curl5);

        // 关闭CURL
        curl_close($curl5);

        $jsonObj5= json_decode($data5);
        $a = $jsonObj5->showapi_res_body->pagebean->songlist;
        // dump($a);die;

        $list = array_slice($a, 0 , 12);
//        处理歌曲的时长
//        将秒数改为
        foreach ($list as $v) {
            $time = $v->seconds;
            if ($time>0) {
                $minute = floor($time/60);
                $second = floor(($time-60 * $minute) % 60);
                if ($second<10) {
                    $second = '0'.$second;
                }
                $result = $minute.':'.$second;
            }
            $v->seconds = $result;
//            var_dump($v->times);

        }




//        新歌速递
        // CURL 初始化
        $curl27 = curl_init();
        $showapi_appid = '79489';  //替换此值,在官网的"我的应用"中找到相关值
        $showapi_secret = '1164663efbe048bcabc9b43fdf3653a6';  //替换此值,在官网的"我的应用"中找到相关值
        $paramArrb = array(
            'showapi_appid'=> $showapi_appid,
            'topid'=> "27"
//添加其他参数
        );

//创建参数(包括签名的处理)
        function createParamb ($paramArrb,$showapi_secret) {
            $paraStr = "";
            $signStr = "";
            ksort($paramArrb);
            foreach ($paramArrb as $key => $val) {
                if ($key != '' && $val != '') {
                    $signStr .= $key.$val;
                    $paraStr .= $key.'='.urlencode($val).'&';
                }
            }
            $signStr .= $showapi_secret;//排好序的参数加上secret,进行md5
            $sign = strtolower(md5($signStr));
            $paraStr .= 'showapi_sign='.$sign;//将md5后的值作为参数,便于服务器的效验
//            echo "排好序的参数:".$signStr."\r\n";
            return $paraStr;
        }
        $param = createParamb($paramArrb,$showapi_secret);
        $url27 = 'http://route.showapi.com/213-4?'.$param;
//        echo "请求的url:".$url."\r\n";die;
        // CURL设置
        curl_setopt($curl27, CURLOPT_URL, $url27);
        // 将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl27, CURLOPT_RETURNTRANSFER, true);
        // 设置为不验证证书和host
//        curl_setopt($curl3, CURLOPT_SSL_VERIFYPEER, false);
//        curl_setopt($curl3, CURLOPT_SSL_VERIFYHOST, false);
        // CURL  执行
        $data27 = curl_exec($curl27);

        // 关闭CURL
        curl_close($curl27);

        $jsonObj27= json_decode($data27);
        $b = $jsonObj27->showapi_res_body->pagebean->songlist;
        // dump($a);die;

        $listb = array_slice($b, 0 , 12);
//        处理歌曲的时长
//        将秒数改为
        foreach ($listb as $v) {
            $time = $v->seconds;
            if ($time>0) {
                $minute = floor($time/60);
                $second = floor(($time-60 * $minute) % 60);
                if ($second<10) {
                    $second = '0'.$second;
                }
                $result = $minute.':'.$second;
            }
            $v->seconds = $result;
//            var_dump($v->times);
        }

//        var_dump($listb);




        //        热歌排行
        // CURL 初始化
        $curl26 = curl_init();
        $showapi_appid = '79489';  //替换此值,在官网的"我的应用"中找到相关值
        $showapi_secret = '1164663efbe048bcabc9b43fdf3653a6';  //替换此值,在官网的"我的应用"中找到相关值
        $paramArrc = array(
            'showapi_appid'=> $showapi_appid,
            'topid'=> "26"
//添加其他参数
        );

//创建参数(包括签名的处理)
        function createParamc ($paramArrc,$showapi_secret) {
            $paraStr = "";
            $signStr = "";
            ksort($paramArrc);
            foreach ($paramArrc as $key => $val) {
                if ($key != '' && $val != '') {
                    $signStr .= $key.$val;
                    $paraStr .= $key.'='.urlencode($val).'&';
                }
            }
            $signStr .= $showapi_secret;//排好序的参数加上secret,进行md5
            $sign = strtolower(md5($signStr));
            $paraStr .= 'showapi_sign='.$sign;//将md5后的值作为参数,便于服务器的效验
//            echo "排好序的参数:".$signStr."\r\n";
            return $paraStr;
        }
        $param = createParamc($paramArrc,$showapi_secret);
        $url26 = 'http://route.showapi.com/213-4?'.$param;
//        echo "请求的url:".$url."\r\n";die;
        // CURL设置
        curl_setopt($curl26, CURLOPT_URL, $url26);
        // 将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl26, CURLOPT_RETURNTRANSFER, true);
        // 设置为不验证证书和host
//        curl_setopt($curl3, CURLOPT_SSL_VERIFYPEER, false);
//        curl_setopt($curl3, CURLOPT_SSL_VERIFYHOST, false);
        // CURL  执行
        $data26 = curl_exec($curl26);

        // 关闭CURL
        curl_close($curl26);

        $jsonObj26= json_decode($data26);
        $c = $jsonObj26->showapi_res_body->pagebean->songlist;
//         dump($c);die;

        $listc = array_slice($c, 0 , 7);
//        dump($listc);
//        处理歌曲的时长
//        将秒数改为
        foreach ($listc as $v) {
            $timec = $v->seconds;
            if ($timec>0) {
                $minutec = floor($timec/60);
                $secondc = floor(($timec-60 * $minutec) % 60);
                if ($secondc<10) {
                    $secondc = '0'.$secondc;
                }
                $resultc = $minutec.':'.$secondc;
            }
            $v->seconds = $resultc;
//            var_dump($v->times);
        }

        return view('home@home/Index',[
            'list'=>$list,
            'listb'=>$listb,
            'listc'=>$listc
        ]);
    }


    public function List()
    {
        return view('home@home/List');
    }
}
